<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>广告列表</title>

<link rel="stylesheet" type="text/css"
	href="${ctx}/resources/media/css/select2_metro.css" />
<link rel="stylesheet"
	href="${ctx}/resources/media/css/DT_bootstrap.css" />
<link rel="stylesheet" href="${ctx}/resources/media/css/dialog.css" />
<style type="text/css">
table {  
word-break:break-all;  
}
</style>
</head>
<body>
	<div class="row-fluid profile">
		<div class="span12">
			<!--BEGIN TABS-->
			<div class="tabbable tabbable-custom tabbable-full-width">
				<ul class="nav nav-tabs">
					<li class="active" id="bannerList"><a href="${ctx}/advert">广告列表</a></li>
					<li id="bannerAdd"><a href="${ctx}/advert/add">广告添加</a></li>
				</ul>
				<div class="tab-content">
                    <div class="alert alert-block alert-warning fade in hide">
                        <button type="button" class="close" data-dismiss="alert"></button>
                        <h4 class="alert-heading">请注意!</h4>
                        <p>
                            你正在执行一个删除操作，你将删除当前被选中的数据。
                            <br/>请确保你知晓执行该操作的后果，该操作不可恢复！
                        </p>
                        <p>
                            <a class="btn red cconfirm" href="javascript:;">继续删除</a> <a class="btn blue cclose" href="javascript:;">放弃操作</a>
                        </p>

                    </div>
					<div class="tab-pane row-fluid active" id="tab_1_1">
						<div class=" responsive" data-tablet="span12 fix-offset">
							<!-- BEGIN EXAMPLE TABLE PORTLET-->
							<div class="portlet box grey">
								<div class="portlet-title">
									<div class="caption">
										<i class="icon-list"></i>广告列表
									</div>
								</div>
								<div class="portlet-body">
                                    <div class="row-fluid">
                                        <div class="span12 ">
                                            <input type="text" placeholder="标题" id="title" class="m-wrap normal">
                                            <select id="status" style="width:150px">
                                            	<option value="-1">全部</option>
                                            	<option value="0">正常</option>
                                            	<option value="1">已删除</option>
                                            </select>
                                            <button class="btn blue" onclick="search()"><i class="icon-search"></i> 搜索</button>
                                        </div>
                                    </div>
									<table class="table table-striped table-bordered table-hover " 
										id="dataTable">
										<thead>
											<tr >
												<th>标题</th>
                                                <th style="width:200px">图片地址</th>
                                                <th>内容</th>
                                                <th style="width:200px">URL</th>
                                                <th>广告类型</th>
                                                <th>产品类型</th>
                                                <th>产品编号</th>
                                                <th style="width:120px">展示起始时间</th>
                                                <th style="width:120px">展示结束时间</th>
                                                <th>排序</th>
                                                <th>状态</th>
												<th style="width:200px">操作</th>
											</tr>
										</thead>
										<tbody>
											
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
					<!--end tab-pane-->
				</div>
			</div>
			<!--END TABS-->
		</div>
	</div>
	<script type="text/javascript" src="${ctx}/resources/media/js/select2.min.js"></script>
	<script type="text/javascript" src="${ctx}/resources/media/js/jquery.dataTables.js"></script>
	<script type="text/javascript" src="${ctx}/resources/media/js/DT_bootstrap.js"></script>
	<script type="text/javascript" src="${ctx}/resources/media/js/form-wizard.js"></script>
	<script type="text/javascript">

        var dt;

		$(function() {
			
			$("select").select2();

			
            dt = $('#dataTable')
					.dataTable(
							{
								"bLengthChange" : false,
								"bFilter" : true,
								"bInfo" : false,
								"iDisplayLength" : 10,
								"bSort" : false,
								"sDom" : "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
								"sPaginationType" : "bootstrap",
                                "bServerSide":true,
                                "sAjaxSource":"${ctx}/advert/data.json",
								"oLanguage" : {
									"oPaginate" : {
										"sPrevious" : "上一页",
										"sNext" : "下一页"
									}
								},
                                "aoColumns":[
                                    {
                                        "mData":"title"
                                    },{
                                        "mData":"image"
                                    },{
                                        "mData":"content"
                                    },{
                                        "mData":"url"
                                    },{
                                    	"mData":null,
                                        "fnRender":function(oObj){
                                            var text = "";
                                            if(oObj.aData.type == 0){
                                                text = "首页轮播";
                                            }
                                            return text;
                                        }
                                    },{
                                    	"mData":null,
                                        "fnRender":function(oObj){
                                            var text = "";
                                            if(oObj.aData.productType == 0){
                                                text = "小豆产品";
                                            } else if(oObj.aData.productType == 1){
                                                text = "美丽产品";
                                            }
                                            return text;
                                        }
                                    },{
                                        "mData":"financingId"
                                    },{
                                        "mData":"publishTime"
                                    },{
                                        "mData":"expiryTime"
                                    },{
                                        "mData":"sort"
                                    },{
                                       	"mData":null,
                                           "fnRender":function(oObj){
                                               var text = "";
                                               if(oObj.aData.status == 0){
                                                   text = "<span class='label label-success'>正常</span>";
                                               } else if(oObj.aData.status == 1){
                                                   text = "<span class='label label-important'>已删除</span>";
                                               }
                                               return text;
                                           }
                                    },{
                                        "mData":null,
                                        "fnRender":function(oObj){
                                        	if(oObj.aData.status == 0){
                                        		return ' <a href="${ctx}/advert/form/'+oObj.aData.id+'" class="btn mini black">\
                                                <i class="icon-pencil"></i> 编辑\
    		                                    </a>\
    		                                    <a href="javascript:del(\''+oObj.aData.id+'\',\''+oObj.aData.code+'\',undefined)" class="btn mini red" onClick="del()">\
    		                                   			 <i class="icon-trash"></i> 删除\
    		                            		</a>';
                                        	} else {
                                        		return null;
                                            }
                                        	
                                        }
                                    }

                                ],
                                "fnServerData":function(sSource,aoData,fnCallback){
                                    for(i in aoData){
                                        if(aoData[i].name == "sSearch")
                                            aoData[i].name = "title";
                                    }

                                    aoData.push({name:'status',value:$("#status").val()});  
                                    $.ajax({
                                        "dataType":'json',
                                        "type":'POST',
                                        "url":sSource,
                                        "data":aoData,
                                        "success":fnCallback
                                    });
                                }
							});

			jQuery('#dataTable_wrapper .row-fluid:first').remove();
			jQuery('#dataTable_wrapper .dataTables_length select').addClass(
					"m-wrap small"); // modify table per page dropdown
		});

        function search(){
            dt.fnFilter($("#title").val());     
        }

        function del(id,title,confirm){
            if(confirm == undefined){
                $(".alert-warning").show();
                //$("strong.title").html(title);
                $(".cclose").click(function(){
                    $(".alert-warning").hide();
                });
                $(".cconfirm").unbind("click");
                $(".cconfirm").bind("click",function(){
                    del(id,title,1);
                })
            }else{
                $.post("${ctx}/advert/delete/"+id,null,function(result){
                    if(result.success){
                        $(".cclose").click();
                        alertBasic("提示信息","删除成功",null,3);
                        search();
                    }else{
                    	alertBasic("提示信息","删除失败",null,1);
                    }
                },"json")
            }
        }
		
	</script>
</body>
</html>